<?
if(!$_SESSION['sid'])
    exit('请登录');
include_once '/var/www/html/new/com.inc.php';
$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$s = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));
$aid=$_SESSION['sid'];
switch ($_POST['ztime']) {
	case '1':
    default:
        $btime=date('Y-m-d',strtotime("-7days"));
		break;
    case '2':
        $btime=date('Y-m-d',strtotime("-30days"));
        break;
    case '3':
        $btime=date('Y-m-d',strtotime("-90days"));
        break;
    case '4':
        if((strtotime($_POST['bt'])-$_SERVER['REQUEST_TIME'])>90*3600*24)//超过90天报错
            exit ("<script>
                            alert('所选时间间隔不能大于三个月');
                            history.go(-1);
                        </script>");
        $btime=$_POST['bt'];
        break;
}
$etime=$_POST['et'] ? $_POST['et']:date('Y-m-d');
$bt = $btime .' 00:00:00';
$et = $etime .' 23:59:59';
$btt = date('Y-m-d',strtotime("-90days"));
$lid_arr=array();
    //自供自销的
//统计所有有销量的景区 最好要用缓存来做
$x_ob1 = simplexml_load_string(
       $s -> Order_Globle_Search(
             "","$aid", "", "", "", "", "", "", "", "",
             "$btt", "$et", "", "", "", "1|5", "", "", "", "",
             "0", "100", "0", "0", "", "0", "0", "0", "", "",
              "", "", "", "", ""
       )
);
$count_json = 0;
foreach($x_ob1->Rec as $key1=>$val1){
    if($val1->UUmid==$val1->UUaid)
        $lid_arr[(int)$val1->UUlid]=(string)$val1->UUltitle;
}

//已卖出的产品
$x_ob2 = simplexml_load_string(
      $s -> Order_Globle_Search(
         "","", "", "", "", "", "", "", "", "",
         "$btt", "$et", "", "", "", "1|5", "", "", "", "",
         "0", "100", "0", "0", "", "0", "0", "0", "", "",
          "$aid", "", "", "", ""
      )
);
foreach($x_ob2->Rec as $key2=>$val2){
    $lid_arr[(int)$val2->UUlid]=(string)$val2->UUltitle;
}
$json_lid = array();
//页面刚载入时 传出前十个景区
if(!$_POST['ltitle'] && $_REQUEST['action'] == 'land_search'){
    foreach ($lid_arr as $k => $v) {
        ++$count_json;
        $json_lid[] = array(
            'id' => $k,
            'ltitle' => $v
        );
        if($count_json>9) break;
    }
}
if($_POST['action'] == 'land_search'){
    if(!$_POST['ltitle']){
        echo json_encode(array(
            'sta' => 'suc',
            'list' => $json_lid
        ));
        exit;

    }
    $n=0;
    //搜索指定景区名时
    foreach($lid_arr as $key => $val){
        if(strpos($val,$_POST['ltitle'])!== false){
            if($n==9) break;
            ++$n;
            $json_lid[] = array('id'=>$key,'ltitle'=>$val);
        }
    }
    exit(json_encode(array('sta'=>'suc','list'=>$json_lid)));
}
//传入了查询的指定几个景区时
if($_POST['lnkprods']){
    if(is_array($_POST['lnkprods'])){
        unset($lid_arr);
        foreach ($_POST['lnkprods'] as $k => $v) {
            $linkprods .=$v.',';
        }
    }
}else if($_POST['linkprods_inp']){
        $linkprods = $_POST['linkprods_inp'];
}
if($linkprods){
    unset($lid_arr);
    $linkprods = rtrim($linkprods,',');
    $sql = "select id,title from uu_land where id in($linkprods)";
    $GLOBALS['le']->query($sql);
    while($row=$GLOBALS['le']->fetch_assoc()){
        $lid_arr[$row['id']] = $row['title'];
    }
}
if(count($lid_arr)!=0){
  if($_POST['lid']=='-1' || !$_POST['lid']){
      foreach($lid_arr as $lid=>$vt){
          $x = $s -> Order_Globle_Search(//卖
             "","", "$lid", "", "", "", "", "", "", "",
             "$bt", "$et", "", "", "", "", "", "", "", "",
             "0", "1800", "2", "0","","0","0", "0","","",
              "$aid", "", "", "", ""
          );
        $x=explode(',',$x);
        $x=$x[1];
        $x2 = simplexml_load_string(
            $s -> Order_Globle_Search(//买
                 "","$aid", "$lid", "", "", "", "", "", "", "",
                 "$bt", "$et", "", "", "", "", "", "", "", "",
                 "0", "1800", "0", "0","","0","0", "0","","",
                      "", "", "", "", ""
             )
         );
      $var=0;
      foreach($x2->Rec as $v){
         $vb=(int)$v->UUpmode;
         if($v->UUmid==$v->UUaid)//自供自销
             $var+=$v->UUtnum;
      }

      $UUt[(string)$vt]=$x+$var;
  }
    }else{
      $x = $s -> Order_Globle_Search(//卖
          "","", $_POST['lid'], "", "", "", "", "", "", "",
          "$bt", "$et", "", "", "", "", "", "", "", "",
          "0", "800", "2", "0","","0","0", "0","","",
          "$aid", "", "", "", ""
      );
      $x=explode(',',$x);
      $x=$x[1];

      $x2 = simplexml_load_string(
          $s -> Order_Globle_Search(//买
              "","$aid", $_POST['lid'], "", "", "", "", "", "", "",
              "$bt", "$et", "", "", "", "", "", "", "", "",
              "0", "800", "0", "0","","0","0", "0","","",
              "", "", "", "", ""
          )
      );
      $var=0;
      foreach($x2->Rec as $v){
          $vb=(int)$v->UUpmode;
          if($vb==3)//自供自销
              $var+=$v->UUtnum;
      }

      $UUt[$_POST['lid']]=$x+$var;
    }
}

//进行降序排序；
//function sortByOrderm($a,$b){
	//if($a['order']>$b['order']) return -1;
	//if($a['order']<$b['order']) return 1;
	//return 0;
//}
   
	//$monthSales= $object->monthSaleOrders();
//	$out=arsort($UUt);
	//取前10位产品；
	$UUt=count($UUt)>=10? array_slice($UUt,0,10):$UUt;
	//$Utitle=array();
	//$Utnum=array();
	//foreach($monthSales as $lid=>$val){
		//$Utitle[]=$val['title'];
		//$Utnum[]=$val['tnum'];
		
		
	//}
	//$Utitle=implode(',',$Utitle);
	//$Utitle=json_encode($Utitle);
	//$Utnum=json_encode($Utnum);
	//$Utitle=substr($Utitle,0,-1);
	//$Utnum=substr($Utnum,0,-1);
	
	//$Utitle=json_encode($Utitle);
//if(count($lid_arr)==0)
//{echo"<script>alert('所选时间段无产品,请重新选择日期！！！');</script>";}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title></title>
	<script language="javascript" src="http://www.12301.cc/js/WdatePicker.js"></script>
	<script language="javascript" src="http://www.12301.cc/js/jquery-1.8.0.min.js"></script>
	 <script type="text/javascript" src="http://www.12301.cc/js/ui/easy.js"></script>  
	<!--<script type="text/javascript" src="http://www.12301.cc/js/easydialog.min.js"></script> -->
	
	<script src="//www.12301.cc/js/echarts-2.2.0/build/dist/echarts.js"></script>
	<link id="htcss" rel="stylesheet" type="text/css" href="http://www.12301.cc/css/ui/zbar.css"/>
</head>
<script type="text/javascript">
$(document).ready(function(e){
    if(navigator.userAgent.indexOf("MSIE")>0){
      if(navigator.userAgent.indexOf("MSIE 7.0")>0){  //判断是否是IE7
          document.getElementById("htcss").href="http://www.12301.cc/css/ui/zbarIE.css"; //根据ID改变style的href路径
        }
      if(navigator.userAgent.indexOf("MSIE 8.0")>0){   //判断是否是IE/
          document.getElementById("htcss").href="http://www.12301.cc/css/ui/zbarIE.css";
        }
    
};
});
</script>
<body>
	<div class="div_top">
		<form action="" method="post"  name="form" id="ti">
			<input type="hidden" name="ztime" id="ztime" value="<?=$_POST['ztime']?>"></input>
			<?if($linkprods){ ?>
			<input type="hidden" name="linkprods_inp" value="<?=$linkprods?>"></input>
			<?}?>
			<div class="order_all">
				<span class="order_ca">销量统计</span> 
				<span class="order_cb">产品</span>
				<span class="order_cc">选择</span>
				<span class="order_cd">（默认显示销售量前十的产品，最多选择10个）</span>
				<div class="order_div"><ul class="order_ul"></ul></div>
			</div>
			<div class="time_select">
				<ul class="time_ul">
					<li  class="time_li weeka  <?=$_POST['ztime']==1?'active':''?>">一周</li>
					<li  class="time_li moutha <?=$_POST['ztime']==2?'active':''?>">一月</li>
					<li  class="time_li springa <?=$_POST['ztime']==3?'active':''?>">一季度</li>
					<li  class="time_li wangt <?=$_POST['ztime']==4?'active':''?>">自定义</li>
				</ul>
				<div class="time_show">
					<span><?=$btime?></span>至 <span><?=$etime?></span>
				</div>
				<div class="time_none">
					<!-- <span class="lt time">自定义时间：</span> -->
					<input type="text" data-t="bt" id="txtStartTime_b" value="<?=$btime?>" name="bt" data-msg="请选择时间段" class="textInp w175 alliNameInp" autocomplete="off"/> 至 
					<input type="text" data-t="et" id="txtEndTime_b" value="<?=$etime?>" name="et" data-msg="请选择时间段" class="textInp w175 alliNameInp" autocomplete="off"/>
					<input type="submit" id="sub" value="确定">
				</div>
			</div>
		</form>
	</div>
	<div id="lnk_prods_list" style="margin-top:10%" >
		<form action="" method="post"   name="name" id="t">
		<input type="hidden" name="ztime" id="ztime" value="<?=$_POST['ztime']?>"></input>
			<ul id="prods_list" class="ul_list">
				<ul id="selected_lnk_prods"></ul>
				<div class="btn_zone">
					<button type="button" id="lnk_prods_cancel" class="ui-button ui-button-sblue">取消</button>
					<button type="button" id="lnk_prods_ok" class="ui-button ui-button-sorange">确定</button>
				</div>
			</ul>
			<div class="sereize">
				<input type="text" class="suggest_input"  autocomplete="off" id="land_a" >
				<i class="iconfont select_icon">&#xe600;</i>
				<ul class="suggest_ul" style="display: none;"></ul>
				<div class="order_div" id="order_lili">
					<ul class="order_ul_a"></ul>
				</div>
			</div>
		</form>
	</div>
<script type="text/javascript" src="http://www.12301.cc/js/ui/zbar.js"></script> 
<div id="main" style="height:400px;width:800px"></div>
    <script type="text/javascript">
        // $('#s2id_land_list').css('width','300px');
        // // 路径配置
        // require.config({
            // paths: {
                // echarts: '//www.12301.cc/js/echarts-2.2.0/build/dist'
            // }
        // });
        
        // // 使用
        // require(
            // [
                // 'echarts',
                // 'echarts/chart/bar' // 使用柱状图就加载bar模块
            // ],
            // function (ec) {
                // // 基于准备好的dom，初始化echarts图表
                // var myChart = ec.init(document.getElementById('main')); 
                
                // var option = {
    // title: {
        // x: 'center',
        // text: '已卖出产品票数统计(包含自供自销)' 
    // },
    // tooltip: {
        // trigger: 'item'
    // },
    // toolbox: {
        // show: false,
        // feature: {
		    // mark : {show: false},
            // dataView: {show: true, readOnly: false},
            // restore: {show: true},
            // saveAsImage: {show: true}
        // }
    // },
    // calculable: true,
    // grid: {
        // borderWidth: 0,
        // y: 80,
        // y2: 60
    // },
    // xAxis: [
        // {
            // type: 'category',
            // show: false,
            // data: [<?
                // if($_POST['lid']=='-1' || !$_POST['lid']){
                // if(is_array($UUt)){
                    // foreach($UUt as $key=>$v){
                        // $str.="'".$key."',";
                    // }
                    // $str=substr($str,0,-1);
                    // echo $str;
                    // }
                // }else{
                    // echo "'".$lid_arr[$_POST['lid']]."'";
                // }
	        // ?>]
        // }
    // ],
    // yAxis: [
        // {
            // type: 'value',
            // show: true
        // }
    // ],
    // series: [
        // {
            // barWidth: 50,
            // name: '产品票数统计',
            // type: 'bar',
            // itemStyle: {
                // normal: {
                    // color: function(params) {
                        // // build a color map as your need.
                        // var colorList = [
                          // '#C1232B','#B5C334','#FCCE10','#E87C25','#27727B',
                           // '#FE8463','#9BCA63','#FAD860','#F3A43B','#60C0DD',
                           // '#D7504B','#C6E579','#F4E001','#F0805A','#26C0C0'
                        // ];
                        // return colorList[params.dataIndex]
                    // },
                    // label: {
                        // show: true,
                        // position: 'top',
                        // formatter: '{b}\n{c}'
                    // }
                // }
            // },
            // data: [<?
            // if(is_array($UUt)){
                // foreach($UUt as $tl=>$v){
                    // $tmp .= "'".$v."',";
                // }
                // $tmp =substr($tmp,0,-1);
                // echo $tmp;
			// }
			// ?>] ,
            // markPoint: {
                // tooltip: {
                    // trigger: 'item',
                    // backgroundColor: 'rgba(0,0,0,0)',
                    // formatter: function(params){
                        // return '<img src="' 
                                // + params.data.symbol.replace('image://', '')
                                // + '"/>';
                    // }
                // },
                // data: [
                   
                // ]
            // }
        // }
    // ]
// };
                // // 为echarts对象加载数据 
                // myChart.setOption(option); 
            // }
        // );
	$(".weeka").click(function(){
		$("#ztime").val("1");
		$(".wangt").removeClass("active");
		$("#ti").submit();
	})
	$(".moutha").click(function(){
		$("#ztime").val("2");
		$(".wangt").removeClass("active");
		$("#ti").submit();
	})
	$(".springa").click(function(){
		$("#ztime").val("3");
		$(".wangt").removeClass("active");
		$("#ti").submit();
		
	})
	$(".wangt").click(function(){
	    $(this).addClass("active");
		$(".weeka").removeClass("active");
		$(".moutha").removeClass("active");
		$(".springa").removeClass("active");
		$(".time_show").css("display","none");
		$(".time_none").css("display","block");
	})
	$("#sub").click(function(){
		$("#ztime").val("4");
	})
	$("#txtStartTime_b").bind("click focus", function () {  
	   var endtimeTf = $dp.$('txtEndTime_b');             
	   WdatePicker({                            
		   maxDate: '#F{$dp.$D(\'txtEndTime_b\')}',      
		   dateFmt: "yyyy-MM-dd",              
		   onpicked: function () { endtimeTf.focus(); }          
		});         
	});          
	$("#txtEndTime_b").bind("click focus", function () {       
		WdatePicker({           
		   minDate: '#F{$dp.$D(\'txtStartTime_b\')}', 
		   dateFmt: "yyyy-MM-dd"       
	   });         
	});

    </script>
<script id="list_template" type="text/template">
	<li class="list">
		{title}<a class="rm" title="删除" href="javascript:;">X</a>
		<input type="hidden" name="lnkprods[]" value="{id}">
	</li>
</script>
</body>
</html>